package com.supermap.dataservice.cloud.mymine;

import com.alibaba.dubbo.config.annotation.Service;
import com.supermap.dataservice.util.JSONUtils;
import com.supermap.dubbo.api.cloud.mymine.MymineService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @description
 * @date 2019年12月12 17:09
 * @email 1301584033@qq.com
 */
@Service
public class MymineServiceImpl implements MymineService {
    @Resource
    private MymineMapper mymineMapper;

    @Override
    public JSONUtils getFarmList(String areaCode,Integer userId,Integer limit) {
        return new JSONUtils().setData(mymineMapper.getFarmList(areaCode,userId,limit));
    }

    @Override
    public JSONUtils getNewAreaRoleMenu(Integer userId) {

        List<Map<String,Object>> maps = mymineMapper.getNewAreaRoleMenu(userId, 3,null);
        for (Map<String,Object> map : maps) {
            List<Map<String,Object>> menuList= getAreaMenuList(map, userId);
            map.put("menuList",menuList);
        }
        List<Map<String,Object>> redu= mymineMapper.getNewAreaRoleMenRedu(userId);
        Map<String,Object> map=new HashMap<>();
        map.put("data",maps);
        map.put("heat",redu);
        return new JSONUtils().setData(map);
    }



    public List<Map<String,Object>> getAreaMenuList(Map<String,Object> map,Integer userId){
        List<Map<String,Object>> sysMenus = new ArrayList<>();
        if((Integer)map.get("category")!=1){
            return  sysMenus;
        }
        List<Map<String,Object>>  sysMenuList=mymineMapper.getNewAreaRoleMenu(userId,((String)map.get("code")).length()+3,(String) map.get("code"));
        for(Map<String,Object> sysMenu1:sysMenuList) {
            if (sysMenu1 != null) {
                List<Map<String,Object>>   sysMenus1=  getAreaMenuList(sysMenu1,userId);
                sysMenu1.put("menuList",sysMenus1);
                sysMenus.add(sysMenu1);
            } else {
                continue;
            }
        }
        return sysMenus;
    }
    @Override
    public JSONUtils putNewMenu(Integer userId, String menuCode) {
        return new JSONUtils().setData(mymineMapper.delNewMenu(userId,menuCode));
    }

    @Override
    public JSONUtils delNewMenu(Integer userId, String menuCode) {
        return new JSONUtils().setData(mymineMapper.putNewMenu(userId,menuCode));
    }

    @Override
    public JSONUtils getNewCorpList(Integer userId) {
       List<Map<String,Object>> maps= mymineMapper.getNewCorpList(userId);
        List<Map<String,Object>> redu= mymineMapper.getNewCorpReduList();
        Map<String,Object> map=new HashMap<>();
        map.put("data",maps);
        map.put("heat",redu);
        return new JSONUtils().setData(map);
    }

    @Override
    public JSONUtils putNewCrop(Integer userId, Integer cropId) {
        return new JSONUtils().setData(mymineMapper.putNewCrop(userId,cropId));
    }

    @Override
    public JSONUtils delNewCrop(Integer userId, Integer cropId) {
        return new JSONUtils().setData(mymineMapper.delNewCrop(userId,cropId));
    }

    @Override
    public JSONUtils getUrl(Integer userId) {
        return new JSONUtils().setData(mymineMapper.getUrl(userId));
    }

    @Override
    public JSONUtils getUserScore(Integer userId) {
        return new JSONUtils().setData(mymineMapper.getUserScore(userId));
    }
}
